package com.tmc.service.intair;

import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tmc.entity.intair.IntairChaseCabin;

@Service
public class IntairChaseCabinServiceImpl {

	private Log logger = LogFactory.getLog(this.getClass());

	@Autowired
	private IntairChaseCabinProcessServiceImpl service;

	public synchronized void run() {
		logger.error("执行一次降舱！");
		List<IntairChaseCabin> tasks = service.findTasks();
		if (tasks == null || tasks.isEmpty()) {
			return;
		}
		ExecutorService threadPool = Executors.newFixedThreadPool(tasks.size());
		for (final IntairChaseCabin task : tasks) {
			threadPool.execute(new Runnable() {
				@Override
				public void run() {
					service.process(task);
				}
			});
		}
	}

}
